package com.gitee.magic.jdbc.persistence.source.jdbc.mapper;

import java.io.IOException;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

import com.gitee.magic.core.exception.ApplicationException;

/**
 * @author start
 */
public class MapperManager {
	
	public void start(String[] paths) {
		for(String classPath:paths) {
			scan(classPath);
		}
	}

	/**
	 * 扫描
	 * @param name
	 */
	public void scan(String name) {
		ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
		String classpath="classpath*:"+name;
		Resource[] resources;
		try {
			resources = resolver.getResources(classpath);
		} catch (IOException e) {
			throw new ApplicationException(e);
		}
		for(Resource r:resources) {
			try {
				SqlTemplate.analysisXml(r.getInputStream());
			} catch (IOException e) {
				throw new ApplicationException(e);
			}
		}
	}
	
}
